package com.qf.advice;

import org.aopalliance.intercept.MethodInterceptor;
import org.aopalliance.intercept.MethodInvocation;

/**
 * 环绕增强类
 * @version v1.0.0
 * @Description:
 * @author: 姜红凯
 * @date: 2022.02.09
 * @since 1.0
 */
public class MyAroundAdvice implements MethodInterceptor {
    @Override
    public Object invoke(MethodInvocation invocation) throws Throwable {

        //执行原始方法 ：如果不调用原始方法不执行
        Object result = null;
        try {
            System.out.println("前置增强");
            result = invocation.proceed();
            System.out.println("后置增强");
        } catch (Throwable throwable) {
            throwable.printStackTrace();
            System.out.println("异常增强");
        } finally {
            System.out.println("无论有没有异常都会执行");
        }
        return result;

    }
}
